package org.bysun.ggcip.http;

import org.apache.http.conn.ssl.TrustStrategy;
import org.bysun.ggcip.Commons;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
 * User: bysun
 * Date: 2014/6/7 0007
 * Time: 15:24
 */
public class MyTrustStrategy implements TrustStrategy {
    @Override
    public boolean isTrusted(X509Certificate[] chain, String authType)
        throws CertificateException {
        boolean useful = false;
        for (X509Certificate x509Certificate : chain) {
            String name = x509Certificate.getSubjectDN().getName().toLowerCase();
            if(name.contains(Commons.PPS.getProperty("google.cert.keyinfo","cn=google.com"))){
                useful = true;
            }
        }
        return useful;
    }
}
